<template>
    <!-- <div>我是商品列表</div> -->
    <div class="list">
        <h1>英雄皮肤列表</h1>
        <!-- <div class="select">
            请输入英雄名称：<input type="text" v-model="title">
            <button @click="search()">搜索</button>
        </div> -->
         <!-- <div class="select">
            请输入英雄名称：<input type="text" >
            <button>搜索</button>
        </div> -->
        <!-- <div class="result">
            <span> 搜索结果：</span>
            <div class="result">
             <div class="item" v-for="heros in this.$store.getters.search" :key="heros.id"> 
                <img class="item-img" :src="heros.src" alt="">
                <div class="item-title">{{heros.title}}</div>
                <div class="item-price">{{heros.price | currency}}</div>
                <div class="item-opt">
                    <button class="btn btn-info" @click="add(heros)">加入购物车</button>
                </div> 
            </div>
        </div>  -->
         <!-- 显示英雄皮肤列表 -->
        <div class="item" v-for="heros in heroslist" :key="heros.id"> 
                <img class="item-img" :src="heros.src" alt="">
                <div class="item-title">{{heros.title}}</div>
                <div class="item-price">{{heros.price | currency}}</div>
                <div class="item-opt">
                    <button class="btn btn-info" @click="add(heros)">加入购物车</button>
                </div>     
        </div>
    </div>
</template>
<style>
   h1{
    margin-top: 60px;
    margin-bottom: 50px !important;
   }
   div{
       font-family: 'Courier New', Courier, monospace;
       font-size: 20px;
   }
</style>
<script>
//导入状态映射函数
import { mapState,mapActions, mapGetters } from 'vuex'

export default{
    // title:'',
    // computed:mapState({
    //     heroslist : state=>state.heros.list
    // }),
    name: 'App',
    data(){
        return {
            title:'',
            //search:''
        }
    },
    computed:{
        ...mapState({
            heroslist : state=>state.heros.list
        }),
        ...mapGetters('heros',{title:'search'})

    },
    methods:mapActions('shopcart',['add']),
    ...mapActions('heros',['search']),
    created(){
        this.$store.dispatch('heros/getList')
    },
    search(){
        this.$store.commit('search',this.title)
    },
    filters:{
        currency(value){
            return '￥'+value
        }
    }
}
</script>
<style scoped>
h1{
    text-align: center;
    font-weight: 600;
    margin-bottom: 0;
    text-shadow: 2px 2px 5px lightgray;
}
.list{
    width: 100%;
    height: 680px;
    position: fixed;
    top:0;
    left:0;
    background:url(~/static/bg3.jpg);
    background-repeat: no-repeat;
    min-width: 1000px;
    background-size:100% 100%;

    /* float: left; */
}
.select{
    margin: 0 auto;
    width: 650px;
    height: 45px;
    margin-top: 20px;
}
 .result{
        width: 100%;
        height: 100px;
        background-color: pink;
        border: 2px grey solid;
        border-radius: 5px;
}
.result>ul>li{
    margin-top: 5px;
    width: 450px;
    height: 100px;
    /* background-color: beige; */
 }
.result>ul>li>img{
    padding-left: 0;
    margin-bottom: 8px;
    float: left;
}  
li{
    list-style-type: none;
}
.item{
    width: 150px;
    height: 210px;
    /* background-color:pink; */
    text-align: center;
    float: left;
    margin-left: 55px;
    margin-top: 20px;
    background-color: rgba(255,255,255,0.5);
    box-shadow: 10px 10px 15px -10px;
}
img{
    width: 83px;
    height: 83px;
    margin-top: 20px;
    border: 2px solid blue;
    border-radius: 10px 0 10px 0;
}


</style>